package cn.tedu.store.conf;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import cn.tedu.store.interceptor.LoginInterceptor;

@Configuration
public class LoginInterceptorConfigurer implements WebMvcConfigurer {

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		
		//拦截白名单
		List<String> patterns=  new ArrayList<>();
		patterns.add("/bootstrap3/**");
		patterns.add("/css/**");
		patterns.add("/images/**");
		patterns.add("/js/**");
		patterns.add("/users/reg");
		patterns.add("/users/login");
		patterns.add("/web/register.html");
		patterns.add("/web/login.html");
		patterns.add("/goods/**");
		patterns.add("/web/index.html");
		patterns.add("/web/product.html");
		
		//添加拦截器
		registry.addInterceptor(new LoginInterceptor()) //配置哪个拦截器，我们创建的LoginInterceptor
			.addPathPatterns("/**") //默认拦截所有
			.excludePathPatterns(patterns); //拦截白名单
	}
	
}
